<!-- subpkg_consult/department/index.vue -->
<script lang="ts" setup>
  import { departmentListApi } from '@/apis/consult'
  import type { DepartData } from '@/types/consult'
  import { computed, ref } from 'vue'

  defineProps<{
    type: string
    illnessType: string
  }>()

  // 1. 调用接口获取科室数据
  const departmentList = ref<DepartData[]>([])
  const getDepartment = async () => {
    const res = await departmentListApi()
    // console.log(res)
    departmentList.value = res
    // console.log(res)
  }
  getDepartment()

  // 2. 一级科室切换
  const currentIndex = ref(0)
  const changeIndex = (index: number) => {
    currentIndex.value = index
  }

  // 3. 二级科室
  // ? 是一定要加
  const childList = computed(() => {
    return departmentList.value[currentIndex.value]?.child
  })
</script>

<template>
  <view class="department-page">
    <scroll-view scroll-y class="department-primary">
      <view
        v-for="(item, index) in departmentList"
        class="department-item"
        :key="item.id"
        :class="{ active: index === currentIndex }"
        @click="changeIndex(index)"
        >{{ item.name }}</view
      >
      <view class="department-item"></view>
    </scroll-view>
    <scroll-view class="department-secondary">
      <navigator
        v-for="child in childList"
        :key="child.id"
        hover-class="none"
        :url="`/subpkg_consult/description/index?type=${type}&illnessType=${illnessType}&depId=${child.id}`"
        class="department-item"
      >
        {{ child.name }}
      </navigator>
    </scroll-view>
  </view>
</template>

<style lang="scss">
  @import './index.scss';
</style>
